<html>

<head>
    <meta charset="utf-8">
    <script type="module">
        import * as sys from "@sys";
        console.log("sys", sys);
        // socket 网络编程
        // https://github.com/saghul/txiki.js/blob/master/examples/echo-server.js
        let tcp = new sys.TCP();
        console.log('tcp', tcp);
        tcp.bind({ ip: "127.0.0.1", port: 3412 });
        tcp.listen();
        let sdiv = document.$("#server");
        sdiv.content(<p>listent...</p>);
        sdiv.on("click", () => {
            tcp.close();
            sdiv.content(<p>closed...</p>);
        })
        while (true) {
            let acc =  tcp.accept().then(con => {
                sdiv.content(<p>accept...</p>);
                console.log(con.getsockname());
                console.log(con.getpeername());
                con.write("hello");
            });
        }
    </script>
</head>

<body>
    <h1>server端</h1>
    <div#server>server状态</div>
</body>


</html>